package com.ycMc.controller;

import com.ycMc.bean.request.ProductBrandRequest;
import com.ycMc.bean.response.ListResponse;
import com.ycMc.bean.response.ObjectResponse;
import com.ycMc.common.bean.Response;
import com.ycMc.domain.ProductBrand;
import com.ycMc.service.ProductBrandService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by libo2 on 2017/8/23.
 */
@RequestMapping("api/productBrand")
@Controller
public class ProductBrandController {

    @Autowired
    private ProductBrandService productBrandService;


    @RequestMapping("insert")
    @ResponseBody
    /**
    *Create by libo2
    *Time:2017/8/23 on 18:50
    *@Request :[request]
    *@Response:com.ycMc.bean.response.Response
    **/
    public Response insert(ProductBrandRequest request){
        Response response = new Response();
        try {
            ProductBrand productBrand = new ProductBrand();
            BeanUtils.copyProperties(request, productBrand);
            productBrandService.insert(productBrand);
            response.setStatusCode(Response.SUCCESS);
            response.setMsg("success");
        }catch (Exception e){
            e.printStackTrace();
            response.setStatusCode(Response.FAILED);
            response.setMsg(e.getMessage());
        }
        return  response;
    }


    /**
     *Create by libo2
     *Time:2017/8/23 on 18:51
     *@Request :[request]
     *@Response:com.ycMc.bean.response.Response
     **/
    @RequestMapping("update")
    @ResponseBody
    public Response update(ProductBrandRequest request){
        Response response = new Response();
        try {
            ProductBrand productBrand = new ProductBrand();
            BeanUtils.copyProperties(request, productBrand);
            productBrandService.update(productBrand);
            response.setStatusCode(Response.SUCCESS);
            response.setMsg("success");
        }catch (Exception e){
            e.printStackTrace();
            response.setStatusCode(Response.FAILED);
            response.setMsg(e.getMessage());
        }
        return  response;
    }


    @RequestMapping("delete")
    @ResponseBody
    /**
    *Create by libo2
    *Time:2017/8/23 on 18:52
    *@Request :[request]
    *@Response:com.ycMc.bean.response.Response
    **/
    public Response delete(ProductBrandRequest request){
        Response response = new Response();
        try {
            productBrandService.delete(request.getId());
            response.setStatusCode(Response.SUCCESS);
            response.setMsg("success");
        }catch (Exception e){
            e.printStackTrace();
            response.setStatusCode(Response.FAILED);
            response.setMsg(e.getMessage());
        }
        return  response;
    }

    @RequestMapping("selectAll")
    @ResponseBody
    /**
    *Create by libo2
    *Time:2017/8/23 on 18:56
    *@Request :[request]
    *@Response:com.ycMc.bean.response.ListResponse
    **/
    public ListResponse selectAll(ProductBrandRequest request){
        ListResponse response = new ListResponse();
        try {
            response.setCommonList(productBrandService.selectAll());

            response.setStatusCode(Response.SUCCESS);
            response.setMsg("success");
        }
        catch (Exception e){
            e.printStackTrace();
            response.setStatusCode(Response.FAILED);
            response.setMsg(e.getMessage());
        }
        return  response;





        }






    @RequestMapping("selectOne")
    @ResponseBody
    public ObjectResponse selectOne(ProductBrandRequest request) {
        ObjectResponse response = new ObjectResponse();
        try {
            response.setObject(productBrandService.selectOne(request.getId()));

            response.setStatusCode(Response.SUCCESS);
            response.setMsg("success");
        } catch (Exception e) {
            e.printStackTrace();
            response.setStatusCode(Response.FAILED);
            response.setMsg(e.getMessage());
        }
        return response;
    }
    
    
}
